
local bingnong = fk.CreateSkill {
  name = "lingling__bingnong",
}

Fk:loadTranslationTable{
  ["lingling__bingnong"] = "兵农",
  [":lingling__bingnong"] = "每回合限一次，你可以将♣牌当【闪】或无次数限制的【杀】使用或打出，若造成伤害，你令一名角色回复1点体力，"..
  "若杀死角色，你重置〖仓实〗。",

  ["#lingling__bingnong"] = "兵农：你可以将♣牌当【杀】或【闪】使用或打出",
  ["#lingling__bingnong-choose"] = "兵农：令一名角色回复1点体力",
}

bingnong:addEffect("viewas", {
  pattern = "slash,jink",
  prompt = "#lingling__bingnong",
  interaction = function(self, player)
    local all_names = {"slash", "jink"}
    local names = player:getViewAsCardNames(bingnong.name, all_names)
    if #names == 0 then return end
    return UI.CardNameBox { choices = names, all_choices = all_names }
  end,
  handly_pile = true,
  card_filter = function(self, player, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).suit == Card.Club
  end,
  view_as = function(self, player, cards)
    if #cards ~= 1 or self.interaction.data == nil then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = bingnong.name
    card:addSubcard(cards[1])
    return card
  end,
  before_use = function (self, player, use)
    use.extraUse = true
  end,
  after_use = function (self, player, use)
    if use.damageDealt and not player.dead then
      local room = player.room
      local targets = table.filter(room.alive_players, function (p)
        return p:isWounded()
      end)
      if #targets > 0 then
        local to = room:askToChoosePlayers(player, {
          min_num = 1,
          max_num = 1,
          targets = targets,
          skill_name = bingnong.name,
          prompt = "#lingling__bingnong-choose",
          cancelable = false,
        })[1]
        room:recover{
          who = to,
          num = 1,
          recoverBy = player,
          skillName = bingnong.name,
        }
      end
    end
  end,
  enabled_at_play = function (self, player)
    return player:usedSkillTimes(bingnong.name, Player.HistoryTurn) == 0
  end,
  enabled_at_response = function (self, player, response)
    return player:usedSkillTimes(bingnong.name, Player.HistoryTurn) == 0
  end,
})

bingnong:addEffect("targetmod", {
  bypass_times = function(self, player, skill, scope, card, to)
    return card and table.contains(card.skillNames, bingnong.name)
  end
})

bingnong:addEffect(fk.Death, {
  can_refresh = function(self, event, target, player, data)
    return data.killer == player and data.damage and data.damage.card and
      table.contains(data.damage.card.skillNames, bingnong.name)
  end,
  on_refresh = function(self, event, target, player, data)
    player:setSkillUseHistory("lingling__cangshi", 0, Player.HistoryGame)
  end,
})

bingnong:addAI(nil, "vs_skill")

return bingnong
